package org.syh.boyangfighthealthclub.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @Author: Ben
 * @Date: 2021/3/8 11:16
 * 数据库连接类
 */
public class JavaDateConnection {
        public Connection getConn() {
            String url = "jdbc:mysql://localhost:3306/boxing?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
            String username = "root";
            String password = "why19991009";
            Connection conn = null;
            try {
                Class.forName("com.mysql.cj.jdbc.Driver");
                conn = DriverManager.getConnection(url, username, password);
            } catch (ClassNotFoundException e) {
                System.out.println("连接失败");
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return conn;
        }

        public  static void closeCon(Connection connection) {
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }finally {
                    System.out.println("数据库连接已关闭");
                }
            }

        }
    }
